package com.uk.data.containers;

import java.io.Serializable;
import java.util.Collection;
import java.util.Random;

import com.uk.data.ejbs.IFaturaBean;
import com.uk.data.entities.BashkiKomuna;
import com.uk.data.entities.Kontrata;
import com.uk.data.entities.Perdorimi;
import com.uk.data.entities.Qarku;
import com.uk.data.entities.Rrethi;
import com.vaadin.data.util.BeanItemContainer;



public class KontrataContainer extends BeanItemContainer<Kontrata> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4788685264446783900L;
	
	public static final Object[] NATURAL_COL_ORDER = new Object[]{"id","emri","mbiemri","adresa","perdorimi", "bashkiKomuna"};
	
	/**
	 * "Human readable" captions for properties in same order as in
	 * NATURAL_COL_ORDER.
	 */
	public static final String[] COL_HEADERS_ALBANIAN = new String[] {
			"Kodi", "Emri", "Mbiemri", "Adresa",
			"Perdorimi", "Bashki/Komuna" };
	
	
	public KontrataContainer()throws InstantiationException, IllegalAccessException {
		super(Kontrata.class);
		
	}
	

	public KontrataContainer(Collection<Kontrata> collection)
			throws IllegalArgumentException {
		super(collection);
		// TODO Auto-generated constructor stub
	}

	public static KontrataContainer createFromEjb( IFaturaBean faturaBean){
		
		
		//KontrataContainer.createWithTestData(faturaBean);
		KontrataContainer kontrataContainer = new KontrataContainer(faturaBean.queryLatestKontrata(11193));
		return kontrataContainer;
		
		
		
	}


	public static KontrataContainer createWithTestData(IFaturaBean faturaBean){
		final Integer[] ids = {123123, 123123, 123, 35, 5464, 657567, 12356, 65757, 68678 ,678};
		final String[] emrat = {"klau","rois","adi","bruno","ladi","baba","mama","daja","hala","nana","gjyshi","dushi","cupi","dashi","rrushi","krajli","jeta","drita","hana","ylli","aba","dada","papa"};
		final String[] mbiemrat = {"mertiku","sokoli","patushi","rrapatushi","roisaku","zemreku","krajli","cupi","dashi","roisi","marroqi","jeta","shpirti","ylli","drita","dilli","majmuni","mica","dada","daja","hala","vici","kihi","zogu","ciuciu"};
		final String[] adresat = { "4215 Blandit Av.", "452-8121 Sem Ave",
				"279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
				"6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
				"161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
				"448-8295 Mi Avenue", "6419 Non Av.",
				"659-2538 Elementum Street", "2205 Quis St.",
				"252-5213 Tincidunt St.", "P.O. Box 175, 4049 Adipiscing Rd.",
				"3217 Nam Ave", "P.O. Box 859, 7661 Auctor St.",
				"2873 Nonummy Av.", "7342 Mi, Avenue",
				"539-3914 Dignissim. Rd.", "539-3675 Magna Avenue",
				"Ap #357-5640 Pharetra Avenue", "416-2983 Posuere Rd.",
				"141-1287 Adipiscing Avenue", "Ap #781-3145 Gravida St.",
				"6897 Suscipit Rd.", "8336 Purus Avenue", "2603 Bibendum. Av.",
				"2870 Vestibulum St.", "Ap #722 Aenean Avenue",
				"446-968 Augue Ave", "1141 Ultricies Street",
				"Ap #992-5769 Nunc Street", "6690 Porttitor Avenue",
				"Ap #105-1700 Risus Street",
				"P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
				"414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
				"561-9262 Iaculis Avenue" };
		
		Integer[] perdorimet = {1,2,3};
		Integer[] qarqet = {1,2,3,4,5,6,7,8,9,10,11,12};
		Integer[]rrethet = {1,2,3,4,5,6,7,8,9,10,23,34,56,67,86,55,34,24,19,52};
		Integer[] bashkiKomunat = {45,656,76,24,546,98,96,344,752,743,89,1346,805,35,435};
		
		KontrataContainer kontrataContainer = null;
		Random r = new Random(0);
		
		try {
			kontrataContainer = new KontrataContainer();
			for (int i = 0; i < 1000000; i++) {
				Kontrata p = new Kontrata();
				//p.setId(ids[r.nextInt(ids.length)]);
				p.setEmri(emrat[r.nextInt(emrat.length)]);
				p.setMbiemri(mbiemrat[r.nextInt(mbiemrat.length)]);
				p.setAdresa(adresat[r.nextInt(adresat.length)]);
				p.setPerdorimi(new Perdorimi(1,"FAMILJAR"));
				
				p.setBashkiKomuna(new BashkiKomuna(1, "SHKODER"));
				
				faturaBean.saveKontrata(p);

				//kontrataContainer.addItem(p);
			}
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return kontrataContainer;
	}
	
	

}
